using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AutoGear.BLL;

public partial class admin_state_tax_edit : SiteAdminBasePage
{
    
    public int _stateTaxId;
    protected void Page_Load(object sender, EventArgs e)
    {
        uccResponseMessage.Visible = false;
        if (!IsPostBack)
        {        
            LoadData();
        }
    }

    private void LoadData()
    {
        int stateTaxId = 0;
        if (!string.IsNullOrEmpty(Request.QueryString["sid"]) &&
            int.TryParse(Request.QueryString["sid"], out stateTaxId))
        {
            StateTax stateTax = StateTax.Load(stateTaxId);
            this.BindData(stateTax);
            _stateTaxId = stateTaxId;
        }

    }
    protected void Update_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            Page.Validate();
            if (Page.IsValid)
            {

                int stateTaxId = 0;
                if (!string.IsNullOrEmpty(Request.QueryString["sid"]) &&
                    int.TryParse(Request.QueryString["sid"], out stateTaxId))
                {
                    StateTax stateTax = StateTax.Load(stateTaxId);
                    double tax;
                    double.TryParse(tbxTax.Text.Trim(),out tax);
                    stateTax.Tax = tax;
                    stateTax.IsActive = cbxIsActive.Checked;                    
                    stateTax.Update();
                    uccResponseMessage.SetSuccessMessage(AutoGearCommonMessage.StateTaxUpdateSuccessful);
                }
            }
        }
        catch
        {
            uccResponseMessage.SetFailMessage(AutoGearCommonMessage.StateTaxUpdateFailed);
            uccResponseMessage.Visible = true;
        }
    }

    private void BindData(StateTax stateTax)
    {
        if (stateTax != null)
        {
            lblStateName.Text = stateTax.StateName;
            tbxTax.Text = stateTax.Tax.ToString() ;
            cbxIsActive.Checked = stateTax.IsActive;
        }
    }
}


